package com.junzhiit.nengji.api.web.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.api.service.RebateService;
import com.junzhiit.nengji.api.web.vo.RebateVO;
import com.junzhiit.nengji.api.web.vo.ResultVO;
import com.junzhiit.nengji.model.RebateInfo;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/rebate")
public class RebateController extends BaseController{

	@Autowired
	private RebateService rebateService;
	
/*	@Autowired
	private CommissionHistoryService commissionHistoryService;*/
	
	@ApiOperation(value = "test")
	@RequestMapping(value = "/test", method = RequestMethod.POST)
	public ResultVO test(RebateVO rebateVO) {
		ResultVO result = new ResultVO();
		for(int i = 0;i<rebateVO.getNumber();i++){
			RebateInfo rebateInfo = rebateService.addRebate(rebateVO);
			if(StringUtils.isNoneBlank(rebateInfo.getId())){
				rebateService.updateRedate(rebateInfo);
			}
			result.setData(rebateInfo);
		}
		return result;
	}
	
/*	@ApiOperation(value = "test/sell")
	@RequestMapping(value = "/test/sell", method = RequestMethod.POST)
	public ResultVO testSell(String userId,String orderId,String parentId) {
		ResultVO result = new ResultVO();
		commissionHistoryService.add(userId, orderId, parentId);//分销
		return result;
	}*/
	
	
	@ApiOperation(value = "根据用户ID查询返利")
	@RequestMapping( method = RequestMethod.GET)
	public ResultVO findGoodsInfo(String userId) {
		AssertUtil.notBlank(userId, "userId is required");
		return rebateService.getRebate(userId);
	}
}
